﻿Partial Public Class Window5

    Public SkinDir As String
    Public SkinFiles As New Dictionary(Of String, IO.FileInfo)

    Delegate Sub ImageUpgrader(ByVal imgSrc As String)
    Public Sub UpgradeImage(ByVal ImageSrc As String)

    End Sub


    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button1.Click
        Dim open As New System.Windows.Forms.OpenFileDialog
        open.Filter = "XAML files(*.xaml)|*.xaml"

        If open.ShowDialog = Forms.DialogResult.OK Then
            Dim ipfile As New IO.FileInfo(open.FileName)
            Dim ipstorage As New IO.FileInfo(ipfile.FullName & ".storage")
            Dim opfile As New IO.FileInfo(OFCDirectory & "\Skins\" & ipfile.Name)
            Dim opdir As New IO.DirectoryInfo(OFCDirectory & "\Skins\" & ipstorage.Name)

            Try
                ipfile.CopyTo(opfile.FullName, True)
                If ipstorage.Exists = True Then
                    ipstorage.CopyTo(opdir.FullName, True)
                End If

                SkinFiles.Add(opfile.Name, opfile)
                ListBox1.Items.Add(opfile.Name)

            Catch ex As Exception
            End Try

        End If
    End Sub

    Private Sub Window5_Loaded(ByVal sender As Object, ByVal e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        Dim sd As New IO.DirectoryInfo(OFCDirectory & "\Skins")
        If sd.Exists = False Then
            sd.Create()
        End If
        For Each file As IO.FileInfo In sd.GetFiles("*.xaml")
            SkinFiles.Add(file.Name, file)
            ListBox1.Items.Add(file.Name)
        Next

    End Sub

    Private Sub ListBox1_SelectionChanged(ByVal sender As System.Object, ByVal e As System.Windows.Controls.SelectionChangedEventArgs) Handles ListBox1.SelectionChanged
        Try
            Dim file As IO.FileInfo = SkinFiles.Item(ListBox1.SelectedItem.ToString)
            Dim rd As ResourceDictionary = Nothing
            Using fs As New IO.FileStream(file.FullName, IO.FileMode.Open, IO.FileAccess.Read)
                rd = CType(Windows.Markup.XamlReader.Load(fs), ResourceDictionary)
            End Using
            Application.Current.Resources = rd
            My.Settings.SkinFile = file.FullName
            My.Settings.Save()
        Catch ex As Exception
        End Try
    End Sub

    Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button2.Click
        Try
            System.Diagnostics.Process.Start(OFCDirectory & "\Skins")
        Catch ex As Exception
            MsgBox(ex.Message)
        End Try
    End Sub

    Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.Windows.RoutedEventArgs) Handles Button4.Click
        My.Settings.SkinFile = ""
        My.Settings.Save()
    End Sub
End Class
